package com.hhc.flyweight;

/**
 * 每个字符都是一个独立的对象，包含内部状态（字符值）和外部状态（位置）。
 * 这会导致内存占用增加，特别是在大量相同字符的情况下，因为每个字符都需要单独创建和维护
 */

// 传统方式下的字符串
class Character {

    private char character;
    private String position;

    public Character(char character, String position) {
        this.character = character;
        this.position = position;
    }

    public void print() {
        System.out.println("Character " + character + " at position " + position);
    }
}

// 客户端
public class TextEditorTraditional {
    public static void main(String[] args) {
        String text = "Hello, World!";
        char[] characters = text.toCharArray();

        for (int i = 0; i < characters.length; i++) {
            Character character = new Character(characters[i], Integer.toString(i));
            character.print();
        }
    }
}
